package com.rd.student.jike.class2.lihongming.week731_806.Day0804;

/**
 * @Auther:Heinrich
 * @Date:2023/8/4-08-04-15:40
 * @Description:com.rd.student.jike.class2.lihongming.Day0804
 * @version:1.0
 */
public class DeadlockTest {
    public static void main(String[] args) {
        ABC abc = new ABC();
        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    abc.getA();
                    abc.getB();
                    abc.getC();
                }
            }).start();
        }
    }
}
class ABC{
    final Object A = new Object();
    final Object B = new Object();
    final Object C = new Object();
    public void getA(){
        synchronized (A){
            synchronized (B){
                System.out.print(Thread.currentThread().getName()+" getA已执行");
                System.out.println(" A->B");
            }
        }
    }
    public void getB(){
        synchronized (B){
            synchronized (C){
                System.out.print(Thread.currentThread().getName()+" getB已执行");
                System.out.println(" B->C");
            }
        }
    }
    public void getC(){
        synchronized (C){
            synchronized (A){
                System.out.print(Thread.currentThread().getName()+" getC已执行");
                System.out.println(" C->A");
            }
        }
    }

}
